package com.cts.tmall.app.controller;

import com.cts.tmall.biz.service.CouponService;
import com.cts.tmall.dal.entity.TmallCoupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

    @GetMapping
    public Map<String, Object> queryCoupon(
            @RequestParam(name = "createUserId", required = false) Long createUserId,
            @RequestParam(name = "couponNo", required = false) String couponNo,
            @RequestParam(name = "couponName", required = false) String couponName,
            @RequestParam(name = "couponType", required = false) String couponType,
            @RequestParam(name = "useStartTime", required = false) String useStartTime,
            @RequestParam(name = "useEndTime", required = false) String useEndTime,
            @RequestParam(name = "status", required = false) String status,
            @RequestParam(name = "couponChannel", required = false) String couponChannel,
            @RequestParam(name = "pageNumb", required = false) Long pageNumb,
            @RequestParam(name = "pageSize", required = false) Long pageSize) throws Exception {
        return couponService.queryCoupon(createUserId,couponNo, couponName, couponType, useStartTime, useEndTime, status, couponChannel, pageNumb, pageSize);
    }

    @PutMapping
    public TmallCoupon updateCoupon(@RequestBody TmallCoupon coupon) {
        return couponService.updateCoupon(coupon);
    }

    @PostMapping
    public TmallCoupon addCoupon(@RequestBody TmallCoupon coupon) {
        return couponService.addCoupon(coupon);
    }
}
